import { defineStore } from 'pinia'

type TUserStore = {
  appId: number // 应用id
  userId: string // 用户id
  roomId: string // 房间id
  appSign: string
  token?: string
  streamID: string
  num: number
}
export const useUserStore = defineStore('userStore', {
  state: (): TUserStore => ({
    appId: 1313839875,
    userId: Math.random().toString(36).substr(2, 8),
    roomId: '10001',
    appSign: '897b57d9aca242a62ca87b122a39c4f44ecb1ba9d689f16a408828e4fb3258b9',
    token:
      '04AAAAAGbO3s8AEHJudGh0bmF5aGZyNmVrYXMAsCvGTWjIC64Eiyi3Yk86wtX4jDB4r10X7vnr9K38vLl5TM6lCVStg6wirF+NTyks9dKYA+Q//dEDhLpezGMuqwSfCJVz/LBTVhdt/19EaqO6PYjh4or+YMiZLiyPUB3IRNhp41m/o2wPN//OWsA35F+PEXP7pqE23vo3d+Z1FzK/FAdAeU0pBTTazFPvxTJZgER/v4DgfeymmNdo39yZ41sRgh0tO//pDtyokxoqqHp/',
    streamID: '',
    num: 0,
  }),
  actions: {
    setToken(token: string) {
      this.token = token
    },
    setUserInfo(userInfo: TUserStore) {
      this.appId = userInfo?.appId
      this.userId = userInfo?.userId
      this.roomId = userInfo?.roomId
      this.appSign = userInfo?.appSign
    },
    setStreamID(streamID: string) {
      this.streamID = streamID
    },
    setNum(num: number) {
      this.num = num
    },
  },
  persist: {
    storage: localStorage,
  },
})
